package com.scy.boot06test02.controller;



import com.scy.boot06test02.demos.web.User;
import com.scy.boot06test02.entity.UserInfo;
import com.scy.boot06test02.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public int reg(@RequestBody UserInfo user){
        System.out.println("user = " + user);
        UserInfo u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            return 2;//用户已存在
        }
        mapper.insert(user);
        return 1;
    }
    @RequestMapping("/login")
    public int login(@RequestBody UserInfo user){
        System.out.println("user = " + user);
        UserInfo u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            if (user.getPassword().equals(u.getPassword())){
                return 1;
            }
           return 2;
        }
        return 3;
    }
}
